//
//  RootViewController.m
//  Arts1
//
//  Created by apple on 15/8/28.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "RootViewController.h"
#import "PrefixHeader.pch"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.tabBar.tintColor = kCustomColor(50, 50, 70, 1);
    [self creactControllers];
    self.selectedIndex = 2;
}

/**
 *  创建控制器Tabbar
 */
- (void)creactControllers
{
    SchoolCLOViewController *SchoolVC = [[SchoolCLOViewController alloc] init];
    [self addOneChildVc:SchoolVC title:nil imageName:@"University_Normal" selectImage:@"University_Select"];
    
    CourseViewController *message1 = [[CourseViewController alloc] init];
    [self addOneChildVc:message1 title:nil imageName:@"Studio_Normal" selectImage:@"Studio_Select"];
    
    HomeListViewController *HomeVC = [[HomeListViewController alloc] init];
    [self addOneChildVc:HomeVC title:nil imageName:@"A1_Normal" selectImage:@"A1_Select"];
    
    MessageViewController *MessageVC = [[MessageViewController alloc] init];
    [self addOneChildVc:MessageVC title:nil imageName:@"Message_Normal" selectImage:@"Message_Select"];
    
    UserViewController *UserVC = [[UserViewController alloc] init];
    [self addOneChildVc:UserVC title:nil imageName:@"User_Normal" selectImage:@"User_Select"];
}

/**
 *  创建TabBar
 *
 *  @param chlidVc     子控制器名字
 *  @param title       下导航栏的标题
 *  @param imageName   下导航栏的图片
 *  @param selectImage 下导航栏选择的图片
 */
- (void)addOneChildVc:(UIViewController *)chlidVc title:(NSString *)title imageName:(NSString *)imageName selectImage:(NSString *)selectImage
{
    //随机色
//    chlidVc.view.backgroundColor = kRandomColor;
    
    //设置导航栏的标题
    chlidVc.tabBarItem.title = title;
    //设置导航栏的图片
    chlidVc.tabBarItem.image = [UIImage imageNamed:imageName];
    UIImage *selectImageMe = [UIImage imageNamed:selectImage];
    
    //是否为iOS7
    if (kiOS7)
    {
        //显示原图，不要渲染,因为在iOS7版本之后会对选择的图片渲染成蓝色
//        selectImageMe = [selectImageMe imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    chlidVc.tabBarItem.selectedImage = selectImageMe;
    chlidVc.tabBarController.tabBar.tintColor = [UIColor redColor];
    chlidVc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:chlidVc];
    
    //添加子控制器
    [self addChildViewController:navi];
}

@end
